package com.fusion.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;


/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Feb 19, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class PublicChatHistory implements Serializable {
	
	private static final long serialVersionUID = 1L;
	private static final int NUMBERS_OF_MESSAGES_IN_HISTORY = 50;

    public static class Entry implements Serializable {

		private static final long serialVersionUID = 1L;
		public long tick;
        public int fromGuid;
        public String message;

        public Entry(long tick, int fromGuid, String message) {
            this.tick = tick;
            this.fromGuid = fromGuid;
            this.message = message;
        }
    }

    private ArrayList<Entry> chatMessages = new ArrayList<Entry>();

    public void addMessage(long tick, int fromGuid, String message) {
        chatMessages.add(new Entry(tick, fromGuid, message));
        if (chatMessages.size() > NUMBERS_OF_MESSAGES_IN_HISTORY) chatMessages.remove(0);
    }

    public Collection<Entry> allMessages() {
        return chatMessages;
    }
}
